package com.yyj.usercenter.users.service.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.yyj.usercenter.common.util.ConstatFinalUtil;
import com.yyj.usercenter.common.util.PageUtil;
import com.yyj.usercenter.users.dao.IAAdminDao;
import com.yyj.usercenter.users.poio.AAdmins;
import com.yyj.usercenter.users.service.IAAdminsService;

@Service("adminService")
public class IAAdminsServiceImp implements IAAdminsService
{
	@Resource
	public IAAdminDao adminsDao;

	/**
	 * 保存一条管理员
	 */
	@Override
	public JSONObject saveOneAdmins(AAdmins admins)
	{
		JSONObject resultjson=new JSONObject();
		int res=adminsDao.save(admins);
		if(res>0)
		{
			resultjson.put("code", "0");
			resultjson.put("info", ConstatFinalUtil.RESOURCE_INFO.get("0"));
			resultjson.put("res", res);
		}
		else
		{
			try
			{
				resultjson.put("code", "1");
				resultjson.put("info", ConstatFinalUtil.RESOURCE_INFO.get("1"));
			} catch (Exception e)
			{
				ConstatFinalUtil.log.error("保存失败",e);
			}
		}
		return resultjson;
	}

	/**
	 * 删除一条管理员
	 */
	@Override
	public JSONObject deleteOneAdmins(AAdmins admins)
	{
		JSONObject resultjson=new JSONObject();
		int res=adminsDao.delete(admins);
		if(res>0)
		{
			resultjson.put("code", "0");
			resultjson.put("info",ConstatFinalUtil.RESOURCE_INFO.get("0"));
			resultjson.put("res", res);
		}
		else
		{
			try
			{
				resultjson.put("code", "3");
				resultjson.put("info", ConstatFinalUtil.RESOURCE_INFO.get("3"));
			} catch (Exception e)
			{
				ConstatFinalUtil.log.error("删除失败",e);
			}
		}
		return resultjson;
	}

	/**
	 * 更新一条管理员
	 */
	@Override
	public JSONObject updateOneAdmins(AAdmins admins)
	{
		JSONObject resultjson=new JSONObject();
		int res=adminsDao.update(admins);
		res=0;
		if(res>0)
		{
			resultjson.put("code", "0");
			resultjson.put("info", ConstatFinalUtil.RESOURCE_INFO.get("0"));
			resultjson.put("res", res);
		}
		else
		{
			try
			{
				resultjson.put("code", "2");
				resultjson.put("info", ConstatFinalUtil.RESOURCE_INFO.get("2"));
			} catch (Exception e)
			{
				ConstatFinalUtil.log.error("更新失败",e);
			}
		}
		return resultjson;
	}

	/**
	 * 查找单条记录
	 */
	@Override
	public AAdmins findOneAdmins(Map<String, Object> map)
	{
		AAdmins admins=adminsDao.findOne(map);
		return admins;
	}

	/**
	 * 查询多条记录
	 */
	@Override
	public List<AAdmins> findSomeCondList(PageUtil page,Map<String, Object> map)
	{
		if(page!=null)
		{
			map.put("keyCount","true");
			map.put("recordStart", page.getCurrStartRecord());
			map.put("pageSize", page.getPageSize());
			List<AAdmins> adminsTotal=adminsDao.findSomeByCond(map);
			if(adminsTotal.size()>0)
			{
				page.setTotalRecord(adminsTotal.get(0).getId());
			}
			
		}
		map.put("keyCount","false");
		List<AAdmins> adminsList=adminsDao.findSomeByCond(map);
		return adminsList;
	}
	
	
	
}
